package com.ymatou.iapi.thirdpartysync.testcase;

import org.junit.After;

import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.thirdpartysync.parameter.*;
import com.ymatou.iapi.thirdpartysync.service.*;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.business.service.ThirdpartysyncCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
/**
*修改推广时间Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdatePromotionProductTime{
	private static UpdatePromotionProductTimeBean updatepromotionproducttimeBean;
	private static UpdatePromotionProductTimeCall updatepromotionproducttimeCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改推广时间Test");
	}

	@Before
	public void caseUp() {
		updatepromotionproducttimeBean=new UpdatePromotionProductTimeBean();
		updatepromotionproducttimeCall=new UpdatePromotionProductTimeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updatepromotionproducttimeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePromotionProductTime_001() {
		Logger.start(true,"修改正在推广中商品，成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(1000);
			//添加推广商品
			ThirdpartysyncCallService.insertPromotionProduct(productId, sellerId, 0.03);
			Thread.sleep(1000);
			//查询id
			int id = ThirdpartysyncCallService.GetPromotionId(productId, addProdReq.getProduct().getProductName());
			Thread.sleep(1000);
			//查询推广stauts
			PromotionDto beforeDto = ThirdpartysyncCallService.GetPromotionProducts(productId, addProdReq.getProduct().getProductName()).get(0);
			updatepromotionproducttimeBean.setId(id);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1,YMTDateUtil.YMDHMS);
			String EndTIme = YMTDateUtil.getBeforeOrNextDay(6,YMTDateUtil.YMDHMS);
			updatepromotionproducttimeBean.setStartTime(StartTime);
			updatepromotionproducttimeBean.setEndTIme(EndTIme);
			updatepromotionproducttimeCall.setData(updatepromotionproducttimeBean);
			updatepromotionproducttimeCall.callService();			
			Logger.verifyEquals(true, updatepromotionproducttimeCall.getJsonObject().get("success").getAsBoolean(), "验证返回");
			PromotionDto afterDto = ThirdpartysyncCallService.GetPromotionProducts(productId, addProdReq.getProduct().getProductName()).get(0);
			Logger.verifyNotEquals(beforeDto.getStartTime(), afterDto.getStartTime(), "前后时间已经被修改");
			Logger.verifyNotEquals(beforeDto.getEndTime(), afterDto.getEndTime(), "前后时间已经被修改");
			
			Logger.verifyEquals(StartTime, afterDto.getStartTime(), "修改后的时间没错");
			Logger.verifyEquals(EndTIme, afterDto.getEndTime(), "修改后的时间没错");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePromotionProductTime_002() {
		Logger.start(true,"商品id错误，成功");
		try {
			updatepromotionproducttimeBean.setId(11223344);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1,YMTDateUtil.YMDHMS);
			String EndTIme = YMTDateUtil.getBeforeOrNextDay(6,YMTDateUtil.YMDHMS);
			updatepromotionproducttimeBean.setStartTime(StartTime);
			updatepromotionproducttimeBean.setEndTIme(EndTIme);
			updatepromotionproducttimeCall.setData(updatepromotionproducttimeBean);
			updatepromotionproducttimeCall.callService();			
			Logger.verifyEquals(true, updatepromotionproducttimeCall.getJsonObject().get("success").getAsBoolean(), "验证返回");
			Logger.verifyEquals("{}", updatepromotionproducttimeCall.getJsonObject().get("data").toString(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
}